;(function () {
	new Vue({
		el: '#buildingAdd',
		data: {
			isDefaultArr: [{name: '是', code: 'Y'}, {name: '否', code: 'N'}],
			buildNatureArr: [],
			OAONatureArr: [],
			buildingId: hlUrlUtil.GetQueryString('buildingId'),
			projectId: hlUrlUtil.GetQueryString('projectId'),
			existingFlag: 'N', //y 新增  n未新增
			extInfoId: '', //附属id
			propertyCode: '#', //是否有产权证
			financeCode: '#' ,//是否进行财务处理
			buildNature: '#', //建筑性质
			OAONature: '#', //权属性质
			assetInfo: '',
			assetType: '',
			assetAddress: '',
			assetPrice: '',
			assetCompany: '',
			getMode: '',
			getTime: '',
			okAssetAreage: '',
			noAssetAreage: '',
			propertyRight: '',
			assetCode: '',
			cardAddress: '',
			cardDate: '',
			cardAreage: '',
			landCode: '',
			subject: '',
			money: '',
			purpose: '',
			reason: '',
			permissions: window.localStorage.getItem('permissions'),
		},
		methods: {
			//建筑性质
			buildNatureDt () {
				hlhttp.get({
					url: 'configure/dict',
					data: {	module_code: 'ZICH', config_name: 'ZC_ARCH_PROP_TYPE'},
					success: (data) => {
						this.buildNatureArr = data;
					}
				})
			},
			//权属性质
			OAONatureDt () {
				hlhttp.get({
					url: 'configure/dict',
					data: {	module_code: 'ZICH', config_name: 'ZC_PR_PROP_TYPE'},
					success: (data) => {
						this.OAONatureArr = data;
					}
				})
			},
			//参数
			itionalData () {
				let data = {
					assets_info: this.assetInfo || '#',
					assets_type_code: '#',
					assets_type: this.assetType || '#',
					architectural_property_code: this.buildNature || '#',
					architectural_property: this.$refs.jzxz.innerHTML == '请选择' ? '#' : this.$refs.jzxz.innerHTML,
					assets_location: this.assetAddress || '#',
					assets_value: this.assetPrice ? this.assetPrice + '' : '#',
					pr_registered_flag: this.propertyCode || '#',
					pr_belong_org: this.assetCompany || '#',
					pr_acquire_way: this.getMode || '#',
					pr_acquire_time: this.getTime || '#',
					pr_acquired_acreage: this.okAssetAreage ? this.okAssetAreage + '' : '#',
					pr_unacquired_acreage: this.noAssetAreage ? this.noAssetAreage + '' : '#',
					pr_cert_type: this.propertyRight || '#',
					pr_cert_no: this.assetCode || '#',
					pr_cert_addr: this.cardAddress || '#',
					pr_cert_issue_date: this.cardDate || '#',
					pr_cert_covered_acreage: this.cardAreage ? this.cardAreage + '' : '#',
					pr_cert_ownership_nature_code: this.OAONature || '#',
					pr_cert_ownership_nature: this.$refs.cqssdw.innerHTML == '请选择' ? '#' : this.$refs.cqssdw.innerHTML,
					land_approval_no: this.landCode || '#',
					financial_treatment_flag: this.financeCode || '#',
					land_planning_usage: this.purpose || '#',
					pr_untreated_reason: this.reason || '#',
					accounting_subjects: this.subject || '#',
					pr_cert_registered_amount: this.money ? this.money + '' : '#'
				}
				return data;
			},

			//新增获取楼宇附加信息
			add () {
				hlhttp.post({
					url: 'project/building_extra_info',
					data: {
						project_id: this.projectId,
						building_id: this.buildingId,
						ext_info: JSON.stringify(this.itionalData())
					},
					success: (data) => {
						this.existingFlag == 'Y';
						this.extInfoId = data.extInfoId;
						hl.toast('保存成功')
					}
				})
			},
			//编辑
			edit () {
				let data = {id: this.extInfoId}
				let obj = Object.assign({},this.itionalData(),data)
				hlhttp.put({
					url: 'project/building_extra_info',
					data: {
						project_id: this.projectId,
						building_id: this.buildingId,
						ext_info: JSON.stringify(obj)
					},
					success: (data) => {
						hl.toast('保存成功')
					}
				})
			},
			submitData () {
				if (this.existingFlag == 'Y') {
					this.edit()
				}
				if (this.existingFlag == 'N') {
					this.add()
				}
			},
			//根据项目id、楼宇id获取楼宇附加信息
			detailDt () {
				hlhttp.get({
					url: 'project/building_extra_info',
					data: {project_id: this.projectId, building_id: this.buildingId},
					success: (data) => {
						this.existingFlag = data.existingFlag;
						if (data.existingFlag == 'N') return;
						this.extInfoId = data.extInfo.id;
						this.assetInfo = data.extInfo.assetsInfo;
						this.assetType = data.extInfo.assetsType;
						this.propertyCode = data.extInfo.prRegisteredFlag ? data.extInfo.prRegisteredFlag : '#';
						this.$refs.zcxx.innerHTML = data.extInfo.prRegisteredFlag ? data.extInfo.prRegisteredFlag == 'Y' ? '是' : '否' : '请选择';
						this.buildNature = data.extInfo.architecturalPropertyCode;
						this.$refs.jzxz.innerHTML = data.extInfo.architecturalProperty ? data.extInfo.architecturalProperty : '请选择';
						this.assetAddress = data.extInfo.assetsLocation;
						this.assetPrice = data.extInfo.assetsValue;
						this.assetCompany = data.extInfo.prBelongOrg;
						this.getMode = data.extInfo.prAcquireWay;
						this.getTime = hlDateUtil.formatUTCDate(data.extInfo.prAcquireTime, 'yyyy-MM-dd');
						this.okAssetAreage = data.extInfo.prAcquiredAcreage;
						this.noAssetAreage = data.extInfo.prUnacquiredAcreage;
						this.propertyRight = data.extInfo.prCertType;
						this.assetCode = data.extInfo.prCertNo;
						this.cardAddress = data.extInfo.prCertAddr;
						this.cardDate = hlDateUtil.formatUTCDate(data.extInfo.prCertIssueDate, 'yyyy-MM-dd');
						this.cardAreage = data.extInfo.prCertCoveredAcreage;
						this.OAONature = data.extInfo.prCertOwnershipNatureCode;
						this.$refs.cqssdw.innerHTML = data.extInfo.prCertOwnershipNature ? data.extInfo.prCertOwnershipNature : '请选择';
						this.financeCode = data.extInfo.financialTreatmentFlag ? data.extInfo.financialTreatmentFlag : '#';
						this.$refs.cwcl.innerHTML = data.extInfo.financialTreatmentFlag ? data.extInfo.financialTreatmentFlag == 'Y' ? '是' : '否' : '请选择';
						this.landCode = data.extInfo.landApprovalNo;
						this.subject = data.extInfo.accountingSubjects;
						this.money = data.extInfo.prCertRegisteredAmount;
						this.purpose = data.extInfo.landPlanningUsage;
						this.reason = data.extInfo.prUntreatedReason;
					}
				})
			}
		},
		mounted () {
			this.buildNatureDt()
			this.OAONatureDt()
			this.detailDt()
			hlSelectUi()
		}
	})
} ())
